﻿<?php
    error_reporting(0);
    define('__ROOT__', dirname(dirname(__FILE__)));
    require_once(__ROOT__.'\config\config.php'); 
    require_once (__ROOT__.'\model\db.php');
    require_once (__ROOT__.'\model\products.php');
    require_once (__ROOT__.'\controller\pagination.php');
    $product = new Products();
    $params = array(
        'offset' => isset($_GET['page']) ? (int) $_GET['page'] : 1
    );
    $products = $product->search($params, $_GET['search']);
    $total = $product->countsearch($_GET['search']);
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
    <title>Home | E-Shopper</title>
    <link href="../css/bootstrap.min.css" rel="stylesheet">
    <link href="../css/font-awesome.min.css" rel="stylesheet">
    <link href="../css/main.css" rel="stylesheet">
    <!--[if lt IE 9]>
    <script src="js/html5shiv.js"></script>
    <script src="js/respond.min.js"></script>
    <![endif]-->       
    <link rel="shortcut icon" href="images/ico/favicon.ico">
    <link rel="apple-touch-icon-precomposed" sizes="144x144" href="images/ico/apple-touch-icon-144-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="114x114" href="images/ico/apple-touch-icon-114-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="72x72" href="images/ico/apple-touch-icon-72-precomposed.png">
    <link rel="apple-touch-icon-precomposed" href="images/ico/apple-touch-icon-57-precomposed.png">
</head><!--/head-->

<body>
	<header id="header"><!--header-->
            <?php
                if(empty($_SESSION))
                    session_start ();
                if(isset($_SESSION['email']))                  
                    require_once (__ROOT__.'/view/header_login_succeed.php');                
                else{
                    require_once (__ROOT__.'/view/header_login.php');
                }
            ?>
	</header><!--/header-->
	<?php
            if(!empty($_GET["action"])){
                require (__ROOT__.'/controller/addcart.php');
                print'<script type="text/javascript">';
                print'location.href = "./view_search_products.php?search='.$_GET['search'].'&page='.$params['offset'].'";';
                print'</script>';
            }    
        ?>
	<section>
		<div class="container">
			<div class="row">
				<?php require_once (__ROOT__.'/view/index_view_category.php'); ?>
				
				<div class="col-sm-9 padding-right">
					
                                    <div class="features_items"><!--features_items-->
						<h2 class="title text-center">SẢN PHẨM</h2>
                                                <?php foreach($products as $productss) : ?>                                              
						<div class="col-sm-4">
							<div class="product-image-wrapper">
								<div class="single-products">
										<div class="productinfo text-center">
                                                                                    <img src="<?php echo HOST ?>/images/product/<?php echo $productss['image'] ?>" alt=""/>
											<h2><?php echo number_format($productss['price'] , 0, ',', '.') ?> Đồng</h2>
											<p><?php echo $productss['name'] ?></p>
                                                                                        <a href="view_search_products.php?search=<?php echo $_GET['search']; ?>&page=<?php echo $params['offset'] ?>&action=add&quantity=1&name=<?php echo $productss['name'] ?>" class="btn btn-default add-to-cart"><i class="fa fa-shopping-cart"></i>Vào giỏ hàng</a>
										</div>
										<div class="product-overlay">
											<div class="overlay-content">
												<h2><?php echo number_format($productss['price'] , 0, ',', '.') ?> Đồng</h2>
												<p><?php echo $productss['name'] ?></p>
                                                                                                <a href="view_search_products.php?search=<?php echo $_GET['search']; ?>&page=<?php echo $params['offset'] ?>&action=add&quantity=1&name=<?php echo $productss['name'] ?>" class="btn btn-default add-to-cart"><i class="fa fa-shopping-cart"></i>Vào giỏ hàng</a>
											</div>
										</div>
								</div>
								<div class="choose">
									<ul class="nav nav-pills nav-justified">
										<li><a href="<?php echo HOST ?>view/view_product-detail.php?id=<?php echo $productss['id'] ?>"><i class="fa fa-plus-square"></i>Chi tiết sản phẩm</a></li>
									</ul>
								</div>
							</div>
						</div>
                                                <?php 
                                                    endforeach; 
                                                ?>
						
                                    </div><!--features_items-->
                                    <ul class="pagination">
                                               <?php
                                                    $pagination = new Pagination();
                                                    $params = array_merge($params, array(
                                                            'current_page' => isset($_GET['page'])?$_GET['page']:1,
                                                            'total_page' => $total,
                                                            'file' => 'view_search_products.php?search='.$_GET['search']
                                                        ));
                                                    echo $pagination->display2($params);
                                                ?>
                                    </ul>
				</div>
			</div>
		</div>
	</section>
	
	<?php  require_once (__ROOT__.'\view\footer.php'); ?>
	

  
    <script src="../js/jquery.js"></script>
	<script src="../js/bootstrap.min.js"></script>
	<script src="js/jquery.scrollUp.min.js"></script>
    <script src="../js/jquery.prettyPhoto.js"></script>
    <script src="../js/main.js"></script>
</body>
</html>